package com.shujia.wyh.test;

import com.shujia.wyh.mysql_jdbc.utils.MySQLTool;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.LinkedList;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        //使用工具类获取连接对象
        Connection conn = MySQLTool.getConnection();
        BufferedWriter bw = new BufferedWriter(new FileWriter("src/com/shujia/wyh/test/c.txt"));
        //获取操作数据库对象
//            statement = conn.createStatement();
        //获取能够防止sql注入问题的数据库操作对象
        PreparedStatement preparedStatement = conn.prepareStatement("select red1,red2,red3,red4,red5,blue1,blue2 from dlt");

        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()){
            String red1 = resultSet.getString(1);
            String red2 = resultSet.getString(2);
            String red3 = resultSet.getString(3);
            String red4 = resultSet.getString(4);
            String red5 = resultSet.getString(5);
            String blue1 = resultSet.getString(6);
            String blue2 = resultSet.getString(7);
            bw.write(red1+" "+red2+" "+red3+" "+red4+" "+red5+" "+blue1+" "+blue2);
            bw.write(",");
            bw.flush();

        }

    }
}
